get binary string python

26

x = 10
print(format(x, '#b')) # 0b1010
print(format(x, 'b')) # 1010
x= 0xF
print(format(x, 'b')) # 1111
print(f'{x:b}') # 1111 (If you knew this format, you are Python Ninja!)
>>> "{0:b}".format(37)
'100101'
>>> format(14, '#010b')
'0b00001110'

Comments

Submit
0 Comments